<!doctype html>
  <head>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src='https://www.googletagmanager.com/gtag/js?id=UA-132775238-1'></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-132775238-1');
    </script>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes'>
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;600&family=Roboto+Mono&display=swap" rel="stylesheet">
    <script type='text/javascript' src='../rapidoc-min.js'></script>
    <script>
      function getRapiDoc(){
        return document.getElementById("thedoc");
      }

      function toggleSchemaStyle () {
        if (getRapiDoc().getAttribute('schema-style') === 'table') {
          getRapiDoc().setAttribute('schema-style', 'tree');
        } else {
          getRapiDoc().setAttribute('schema-style', 'table');
        }
      }

      function toggleReadOnly(value) {
        const el = document.getElementById('read-only-' + value);
        const neverBox = document.getElementById('read-only-never');
        const options = document.getElementsByClassName('read-only-option');
        neverBox.checked = false;
        let optionsStr = '';
        Array.prototype.forEach.call(options, function (el) {
          if (el.checked) {
            optionsStr = optionsStr + ' ' + el.value;
          }
        });

        if (optionsStr.trim() === '') {
          getRapiDoc().removeAttribute('schema-hide-read-only');
          getRapiDoc().connectedCallback();
        }
        else {
          getRapiDoc().setAttribute('schema-hide-read-only', optionsStr);
        }
      }

      function toggleNeverHideReadOnly(neverBox)
      {
        const options = document.getElementsByClassName('read-only-option');

        if (neverBox.checked) {
          Array.prototype.forEach.call(options, function (el) {
            el.checked = false;
          });
          getRapiDoc().setAttribute('schema-hide-read-only', 'never');
        } else {
          getRapiDoc().removeAttribute('schema-hide-read-only');
          getRapiDoc().connectedCallback();
        }
      }

      function toggleNeverHideWriteOnly(neverBox)
      {
        if (neverBox.checked) {
          getRapiDoc().setAttribute('schema-hide-write-only', 'never');
        } else {
          getRapiDoc().removeAttribute('schema-hide-write-only');
          getRapiDoc().connectedCallback();
        }
      }
    </script>
    <style>
      .btn{
        width: 70px;
        height: 70px;
        background-color: #47AFE8;
        color: #fff;
        font-size: 12px;
        display: block;
        border: none;
        margin: 2px;
        border-radius: 2px;
        cursor:pointer;
        outline:none;
      }
      rapi-doc{
        width:100%;
      }
    </style>
  </head>
  <body>
    <rapi-doc spec-url="../specs/readOnly-writeOnly.json"
      id="thedoc"
      show-info = "false"
      show-header = "false"
      render-style = "read"
      allow-try = "false"
      schema-style = "table"
      regular-font = 'Open Sans'
      mono-font = "Roboto Mono"
      allow-authentication = "false"
      sort-endpoints-by="summary"
    >
      <div style="display:flex; margin:10px; justify-content:center;flex-wrap: wrap;">
        <button class="btn" onclick="toggleSchemaStyle()">Toggle Schema Style</button>
      </div>
      <div style="display:flex; margin:10px; flex-direction: column;"><strong>Hide ReadOnly properties:</strong>
        <div><input type="checkbox" id="read-only-never" onclick="toggleNeverHideReadOnly(this)" /><label for="read-only-never">Never</label></div>
        <div><input type="checkbox" class="read-only-option" id="read-only-post" value="post" onclick="toggleReadOnly('post')" /><label for="read-only-post">POST</label></div>
        <div><input type="checkbox" class="read-only-option" id="read-only-put" value="put" onclick="toggleReadOnly('put')" /><label for="read-only-put">PUT</label></div>
        <div><input type="checkbox" class="read-only-option" id="read-only-patch" value="patch" onclick="toggleReadOnly('patch')" /><label for="read-only-patch">PATCH</label></div>
      </div>
      <div style="display:flex; margin:10px; flex-direction: column;"><strong>Hide WriteOnly properties:</strong>
        <div><input type="checkbox" id="write-only-never" onclick="toggleNeverHideWriteOnly(this)" /><label for="write-only-never">Never</label></div>
      </div>
    </rapi-doc>
  </body>
</html>
